package com.kaigejava.juc;

import com.google.common.collect.Lists;
import com.sun.org.apache.regexp.internal.RE;
import lombok.Data;

import java.util.List;

/**
 * @author kaigejava
 * 需求：
 * 向list里面添加数据，当list的长度为10的时候，sleep 5s
 * 线程demo
 */
@Data
public class ThreadDemo  implements  Runnable{
    private  volatile boolean flag = false;
    List<Integer> list = Lists.newArrayList();
    @Override
    public void run() {
        int i = 0;
        for(;;){
            ++i;

            list.add(i);
            if(list.size() == 5){
                try {
                    Thread.sleep(5000);
                    flag = true;
                    System.out.println("当前标记为:"+this.getFlag());
                    break;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    public static void main(String[] args) {
        ThreadDemo threadDemo = new ThreadDemo();
        new Thread(threadDemo).start();
        for(;;){
            if(threadDemo.getFlag()){
                System.out.println("======");
                break;
            }else{
                System.out.println("+++++++++++++++");
            }

        }
    }
    public boolean getFlag(){
        return flag;
    }
}
